import org.omg.PortableInterceptor.INACTIVE;

import java.util.*;

public class exercise {

    public static HashMap<Integer,Integer> a = new HashMap<>();
    public static void main(String[] args) {
        int[] arr = new int[1026];
        for (int i = 1; i <= 1025 ; i++) {
            arr[i] = i;
        }
        int count = 0;
        for (int i = 1; i <= 1025; i++) {
            count = 0;
            recursionBinarySearch(arr, i, 1, 1025,count);
        }
        System.out.println(a);

        List<Map.Entry<Integer,Integer>> list = new ArrayList<Map.Entry<Integer,Integer>>(a.entrySet());
        Collections.sort(list,new Comparator<Map.Entry<Integer,Integer>>() {
            //升序排序
            public int compare(Map.Entry<Integer,Integer> o1,
                               Map.Entry<Integer,Integer> o2) {
                return o1.getValue().compareTo(o2.getValue());
            }

        });

        for(Map.Entry<Integer,Integer> mapping:list){
            System.out.println(mapping.getKey()+":"+mapping.getValue());
        }

//        for (int i = 1; i <= 1025; i++) {
//            if(a.get(i) == 11){
//                System.out.println(i+":"+a.get(i));
//            }
//        }

    }

    public static int recursionBinarySearch(int[] arr,int key,int low,int high,int count){

        if(key < arr[low] || key > arr[high] || low > high){
            return -1;
        }

        int middle = (low + high) / 2;			//初始中间位置
        if((low+high)%2 !=0){
            middle+=1;
        }
        if(arr[middle] > key){
            //比关键字大则关键字在左区域
            return recursionBinarySearch(arr, key, low, middle - 1,count+1);
        }else if(arr[middle] < key){
            //比关键字小则关键字在右区域
            return recursionBinarySearch(arr, key, middle + 1, high,count+1);
        }else {
            a.put(key,count+1);
            return middle;

        }

    }
}
